// pages/blessingList/blessingList.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:{},
    list:[],
    totalPages:0,
    totalPages1:0,
    pageNumber:1,
    pageNumber1: 1,
    delindex: null,
  },
  godetails(e){
    var id= e.currentTarget.dataset.id
    var type = e.currentTarget.dataset.type
    if(type==1){
      wx.navigateTo({
        url: '/pages/ordinaryDetails/ordinaryDetails?id=' + id,
      })
    }else{
      wx.navigateTo({
        url: '/pages/hundredDetailed/hundredDetailed?id=' + id + "&type="+type,
      })
    }
  },
  hidedel() {
    this.setData({
      delindex:null
    })
  },
  showdel(e) {
    var index = e.currentTarget.dataset.index
    console.log('index', index)
    this.setData({
      delindex: index
    })
  },
  preventTouchMove() { },
  getdel(){
    var that = this
    app.req({
      url: 'blessmini/user/userBlessList',
      data: {
        pageSize: 10,
        pageNumber: that.data.pageNumber1
      },
      method: 'POST',
      success: function (res) {
        console.log('列表', res.data.rows);
        if (res.code == 200) {
          for (var i in res.data.rows) {
            res.data.rows[i].actStartTime = res.data.rows[i].actStartTime.substring(0, 10)
          }
          if (that.data.pageNumber == 1) {
            that.setData({
              list: res.data.rows,
              totalPages1: res.data.totalPages
            })
          } else {
            that.setData({
              list: that.data.list.concat(res.data.rows),
              totalPages1: res.data.totalPages
            })
          }
        }
      }
    })
  },
  delbtn(e){
    var that = this
    var id = e.currentTarget.dataset.id
    var type = e.currentTarget.dataset.type
    wx.showModal({
      content: '请确认是否删除',
      cancelText: "取消",
      confirmText: "确定",
      confirmColor: '#3680FE',
      cancelColor: '#333333',
      success(res) {
        if (res.confirm) {
          app.req({
            url: 'blessmini/user/userDeleteAct',
            data: {
              actId: id,
              type:type
            },
            method: 'POST',
            success: function (res) {
              console.log('返回', res);
              if (res.code == 200) {
                wx.showToast({
                  title: '删除成功',
                  duration: 2000
                })
                that.onShow()
              } else {
                wx.showToast({
                  title: res.msg,
                  icon: 'none',
                  duration: 2000
                })
              }
            }
          })
        }
      }
    })
  },
  // 活动恢复
  recovery(e) {
    var that = this
    var actid = e.currentTarget.dataset.id
    wx.showModal({
      content: '请确认是否恢复',
      cancelText: "取消",
      confirmText: "确定",
      confirmColor: '#3680FE',
      cancelColor: '#333333',
      success(res) {
        if (res.confirm) {
          app.req({
            url: 'blessmini/user/userRestoreAct',
            data: {
              id: actid
            },
            method: 'POST',
            success: function (res) {
              console.log('返回', res);
              if (res.code == 200) {
                wx.showToast({
                  title: '恢复成功',
                  duration: 2000
                })
                that.onShow()
              } else {
                wx.showToast({
                  title: res.msg,
                  icon: 'none',
                  duration: 2000
                })
              }
            }
          })
        }
      }
    })
  },
  // 彻底删除
  thoroughdel(e) {
    var that = this
    var actid = e.currentTarget.dataset.id
    wx.showModal({
      content: '彻底删除后，您将无法恢复此内容，请确认是否彻底删除',
      cancelText: "取消",
      confirmText: "确定",
      confirmColor: '#3680FE',
      cancelColor: '#333333',
      success(res) {
        if (res.confirm) {
          app.req({
            url: 'blessmini/user/userCompleteAct',
            data: {
              id: actid
            },
            method: 'POST',
            success: function (res) {
              console.log('返回', res);
              if (res.code == 200) {
                wx.showToast({
                  title: '彻底删除成功',
                  duration: 2000
                })
                that.onShow()
              } else {
                wx.showToast({
                  title: res.msg,
                  icon: 'none',
                  duration: 2000
                })
              }
            }
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    app.getUserInfo(function (userInfo) {
      that.setData({
        userInfo: userInfo
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    that.setData({
      pageNumber:1,
      pageNumber1:1
    })
      that.getdel()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.onShow()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
      if (that.data.totalPages1 > that.data.pageNumber1) {
        that.setData({
          pageNumber1: that.data.pageNumber1+ 1
        })
        that.getdel()
      }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})